package com.wqtz.chechai.presenter;

import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVObject;
import com.avos.avoscloud.AVQuery;
import com.avos.avoscloud.AVUser;
import com.avos.avoscloud.FindCallback;
import com.avos.avoscloud.LogInCallback;
import com.orhanobut.logger.Logger;
import com.umeng.analytics.MobclickAgent;
import com.wqtz.chechai.presenter.impl.IloginPresenterImpl;
import com.wqtz.chechai.utils.StringUtils;
import com.wqtz.chechai.utils.ToastUtils;
import com.wqtz.chechai.view.impl.IloginViewImpl;

import java.util.List;

/**
 * 项目名称： CheChai
 * 创建人 : Liberation
 * 创建时间: 2016/12/16 10:43
 */

public class LoginPresenter implements IloginPresenterImpl {
	IloginViewImpl mIloginView;
	String name ;
	String pwd;


	public LoginPresenter(IloginViewImpl iloginView) {
		mIloginView = iloginView;
	}


	@Override
	public Boolean login(Context context, String userName, String password) {
		name = userName;
		pwd  = password;
		mIloginView.showLoading();
		Logger.e(name+pwd);
		final Boolean[] isSuccess = new Boolean[1];
		AVUser.logInInBackground(userName, password, new LogInCallback<AVUser>() {
			@Override
			public void done(AVUser avUser, AVException e) {
				if (e == null) {
					mIloginView.moveToIndex();
					mIloginView.hideLoading();
					isSuccess[0] =true;
				} else {
					mIloginView.showError(e.getMessage(),e.getCode());
					isSuccess[0] = false;
				}
			}
		});
		//当用户使用自有账号登录时，umeng进行统计：
		MobclickAgent.onProfileSignIn(userName);
		//当用户使用第三方账号（如新浪微博）登录时，umeng进行统计：
//		MobclickAgent.onProfileSignIn("WB",userName);
		return isSuccess[0];
	}

	@Override
	public Boolean loginOut(Context context, String userName, String password) {
		return null;
	}

	@Override
	public Boolean saveToDB(Context context, String userName, String password) {
		return null;
	}
}
